package com.wn.netty.buffer;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;

/**
 * @FileName: UnpooledTest
 * @Description: TODO
 * @Author: MaWenHao
 * @Created: 2020/8/3 - 17:07
 * @Version: V1.0
 * @Company: 东方微银科技（北京）有限公司
 */
public class UnpooledTest {

    public static void main(String[] args) {
        ByteBuf buffer1 = Unpooled.buffer(8);
        ByteBuf buffer2 = Unpooled.copiedBuffer("hello world!", CharsetUtil.UTF_8);

        if (buffer2.hasArray()) {
            // 获取内容数组
            byte[] content = buffer2.array();
            // 获取偏移量
            System.out.println(buffer2.arrayOffset());
            // 获取读索引
            System.out.println(buffer2.readerIndex());
            // 获取写索引
            System.out.println(buffer2.writerIndex());
            // 获取容量
            System.out.println(buffer2.capacity());
            // 获取可读取长度
            System.out.println(buffer2.readableBytes());
            // 读取部分字符串
            System.out.println(buffer2.getCharSequence(3, 5, CharsetUtil.UTF_8));
        }
    }
}
